package com.wwlwxg.jdk.rs;

import com.wwlwxg.jdk.rs.server.HelloWorldRs;
import com.wwlwxg.jdk.rs.server.HelloWorldRsImpl;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;

public class RsServer {

    public static void main(String[] args) {
        System.out.println("web service start ... ");

        HelloWorldRs helloWorld = new HelloWorldRsImpl();
        String address = "http://192.168.56.1/helloworld";
//        Endpoint.publish(address, helloWorld);

        // 创建工厂对象
        JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();

        // 设置参数
        factoryBean.setAddress(address);
//        factoryBean.setServiceClass(HelloWorld.class);

        // 设置实现类对象
        factoryBean.setServiceBean(helloWorld);

        // 设置日志拦截器
        // 输入拦截器
        factoryBean.getInInterceptors().add(new LoggingInInterceptor());

        // 输出拦截器
        factoryBean.getInInterceptors().add(new LoggingOutInterceptor());

        // 发布服务（阻塞方式）
        factoryBean.create();

        System.out.println("web service started");
    }
}
